'use strict';

angular.module('App').controller('PatchNewController', ['$scope', 'BaseFunction', 'BaseModule', 'BaseEnum', '$location', 'Authentication',
    function($scope, BaseFunction, BaseModule, BaseEnum, $location, Authentication) {
    	$scope.DeviceTypeEnum = BaseFunction.getEnum('AppEnum.DeviceType');

    	BaseModule.initModule($scope, 'App');
        // $scope.Module.App.LoadMode = BaseEnum.LoadMode.CacheAndPaging;
        // $scope.Module.App.PageSize = 15;
        // $scope.Module.App.OrderBy = {Name: 1, Code: 1};
        // $scope.Module.App.AfterOnLoad = function(records){
        //     for(var i=0; i<records.length; i++){
        //         if(records[i].DisplayImage != undefined && records[i].DisplayImage != null && records[i].DisplayImage.trim().length > 0){
        //             records[i].IsImg = true;
        //         }
        //         if(records[i].MouseDownImage != undefined && records[i].MouseDownImage != null && records[i].MouseDownImage.trim().length > 0){
        //             records[i].IsDownImg = true;
        //         }
        //     }
        // };
        $scope.patch = null;
        function initData(){
            BaseFunction.loading(true);
            $scope.Module.App.find({"Type" : 3},null,null,function(records){
                 $scope.patch = records[0];
                 BaseFunction.loading(false);
            })
        }
        initData();

        
        
        $scope.addPatch = function(){
            if($scope.patch._id){
                // $scope.$apply(function(){
                    $location.url("/index/PatchNew/Add/" + $scope.patch._id);
                // });
            }else{
                $location.url('/index/PatchNew/Add');
            }
        	
        };

        $scope.btnDelete = function(){
        	$scope.Module.App.deleteSelecteds();
        };
    }
]);
